import 'package:flutter/material.dart';
import 'package:flutter_09_game/generated/assets.dart';
import 'package:flutter_09_game/widgets/empty/empty_no_data.dart';
import 'package:flutter_09_game/widgets/image/auto_image.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import '../../../config/app_color.dart';
import '../../../config/app_config.dart';
import '../home_logic.dart';
import '../models/model_home_game.dart';
import '../../../widgets/button/debounce_gesture_detector.dart';
import '../../../widgets/image/image_view.dart';

/// 首页游戏列表Grid组件
class HomeGameGrid extends StatelessWidget {
  const HomeGameGrid({super.key, required this.logic});

  final HomeLogic logic;

  @override
  Widget build(BuildContext context) {
    return Obx(() {
      if (logic.currentGameList.isEmpty) {
        return EmptyNoData.notYetView();
      }
      double spacing = (1.sw - 32.w - 109.w * 3) ~/ 2 * 1.0;
      return Container(
        padding: EdgeInsets.symmetric(horizontal: 16.w),

        child: Wrap(
          spacing: spacing,
          runSpacing: spacing,
          children: logic.currentGameList.map((gameItem) {
            return _buildGameItem(logic, gameItem);
          }).toList(),
        ),
      );
    });
  }

  /// 构建单个游戏项
  Widget _buildGameItem(HomeLogic logic, dynamic gameItem) {

    return DebounceGestureDetector(
      onTap: () => logic.handleGameItemTap(gameItem),
      child: ImageView(

        imageUrl: gameItem.image,
        radius: 12.w,
        width: 109.w,
        height: 109.w,
      ),
    );
  }



}
